package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;

import model.Duty;
import model.RewAndPunType;
import dao.RewAndPunTypeDAO;

public class RewAndPunTypeDAOImp implements RewAndPunTypeDAO {


	private DBUtil dbu = new DBUtil();
	private Connection conn = null;
	private PreparedStatement pstat = null;
	private ResultSet rs = null;
	
	
	public List<RewAndPunType> getAll() {
		List<RewAndPunType> list = new ArrayList<RewAndPunType>();
		conn=dbu.getConnection();
		try {
			pstat=conn.prepareStatement("select * from RewAndPunType");
			rs=pstat.executeQuery();
			
			while(rs.next()){
				RewAndPunType rapt = new RewAndPunType();
				rapt.setId(rs.getInt("ID"));
				rapt.setType(rs.getString("TYPE"));
				
				list.add(rapt);
			}
			
		} catch (SQLException e) {

			e.printStackTrace();
		}finally{
			dbu.closeConnection(conn, pstat, rs);
		}
		return list;

	}

	public RewAndPunType getById(int id) {
		conn= dbu.getConnection();
		RewAndPunType rapt = new RewAndPunType();
		try {
			pstat=conn.prepareStatement("select (id,name) from duty where id="+id);
			rs=	pstat.executeQuery();
			rapt.setId(rs.getInt("ID"));
			rapt.setType(rs.getString("TYPE"));
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}finally{
			dbu.closeConnection(conn, pstat, rs);
		}
		return rapt;
	}
	
	
}
